package org.simpatia;

import java.util.Map;
import java.util.TreeMap;

public class SimpatiaServiceImpl implements Service<Void, SimpatiaService>, SimpatiaService {

    private SimpatiaContainer container;

    public void activate(String name, Void aVoid, Context context) {
    }

    public void destroy() {
        container.stop();
    }

    public SimpatiaService getRESTInterface() {
        return this;
    }

    public Map<String, ServiceDescription> listServices() {
        Map<String, Module> services = container.getServices();

        Map<String, ServiceDescription> result = new TreeMap<String, ServiceDescription>();
        for(String serviceName : services.keySet()) {
            ServiceDescription description = new ServiceDescription();
            description.setConfiguration(services.get(serviceName).getConfiguration());

            result.put(serviceName, description);
        }

        return result;
    }

    public void createService(ServiceConfiguration configuration) {
        container.createService(configuration);
    }

    public void destroyService(String serviceName) {
        container.destroyService(serviceName);
    }

    public void reconfigure(String jsonConfiguration) {

    }

    public void registerService(String serviceName, Module module) {
    }

    public void unregisterService(String serviceName) {
    }

    public void setContainer(SimpatiaContainer container) {
        this.container = container;
    }
}
